package com.bawei.mall.product.controller;

import com.bawei.common.core.domain.R;
import com.bawei.mall.product.domain.MallProductCarInfo;
import com.bawei.mall.product.domain.reponse.MallProductCarInfoResponse;
import com.bawei.mall.product.domain.request.ProductCarInfoRequest;
import com.bawei.mall.product.service.IMallProductCarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：韩丹阳
 * @Package：com.bawei.mall.product.controller
 * @Project：mall_cloud
 * @name：MallProductCarInfoController
 * @Date：2024/7/5 下午 04:50
 */
@RestController
@RequestMapping("/car")
public class MallProductCarInfoController {

    @Autowired
    private IMallProductCarInfoService mallProductCarInfoService;

    /**
     * 购物车列表
     * @return
     */
    @GetMapping("/findCarList")
    public R findCarList(){
        List<MallProductCarInfoResponse> mallProductCarInfos = mallProductCarInfoService.findCarList();
        return R.ok(mallProductCarInfos);
    }

    /**
     * 加入购物车
     * @param mallProductCarInfo
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody MallProductCarInfo mallProductCarInfo){
        mallProductCarInfoService.add(mallProductCarInfo);
        return R.ok();
    }


    /**
     * 清空购物车
     */
    @PostMapping("/clear")
    public R clear(){
        mallProductCarInfoService.clear();
        return R.ok();
    }


    /**
     * 单个删除购物车商品
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestParam("ids") Integer ids){
        mallProductCarInfoService.delete(ids);
        return R.ok();
    }

    @GetMapping("/updQuantity")
    public R updQuantity(@RequestParam("id") Integer id,@RequestParam("quantity") Integer quantity){
        mallProductCarInfoService.updQuantity(id,quantity);
        return R.ok();
    }


}
